package fantasyfootball.data.entities;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

/**
 * Class: 605.441 
 * Group: Richard Koretke, Kay Jantharasorn, Israel Rivera.
 * 
 * @author Israel Rivera
 * 
 */
@Entity(name="FantasyLeague")
public class FantasyLeague implements Serializable{

	private static final long serialVersionUID = 2037748696551762873L;
	
	private String leagueName;
	private FantasyManager fantasyManager;
	private Integer minTeams;
	private Integer maxTeams;
	private Character password;
	
	private Set<FantasyTeam> fantasyTeams;
	
	@Id
	@Column(name="LeagueName", nullable=false)
	public String getLeagueName() {
		return leagueName;
	}
	
	public void setLeagueName(String leagueName) {
		this.leagueName = leagueName;
	}
	
	@JoinColumn(name="Commissioner", nullable=false)
	@ManyToOne(fetch=FetchType.LAZY, optional=false)
	public FantasyManager getFantasyManager() {
		return fantasyManager;
	}
	
	public void setFantasyManager(FantasyManager fantasyManager) {
		this.fantasyManager = fantasyManager;
	}
	
	@Column(name="MinTeams", nullable=false)
	public Integer getMinTeams() {
		return minTeams;
	}
	
	public void setMinTeams(Integer minTeams) {
		this.minTeams = minTeams;
	}
	
	@Column(name="MaxTeams", nullable=false)
	public Integer getMaxTeams() {
		return maxTeams;
	}
	
	public void setMaxTeams(Integer maxTeams) {
		this.maxTeams = maxTeams;
	}
	
	@Column(name="Password", nullable=false)
	public Character getPassword() {
		return password;
	}
	
	public void setPassword(Character password) {
		this.password = password;
	}
	
	@OneToMany(fetch=FetchType.LAZY, mappedBy="fantasyLeague")
	public Set<FantasyTeam> getFantasyTeams() {
		return fantasyTeams;
	}

	public void setFantasyTeams(Set<FantasyTeam> fantasyTeams) {
		this.fantasyTeams = fantasyTeams;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((leagueName == null) ? 0 : leagueName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		FantasyLeague other = (FantasyLeague) obj;
		if (leagueName == null) {
			if (other.leagueName != null)
				return false;
		} else if (!leagueName.equals(other.leagueName))
			return false;
		return true;
	}
}